/* 数据处理方法*/

import type { ItemType } from 'ant-design-vue';

import type { VueElement } from 'vue';

/**
 * 获取Antd a-menu组件的列表项
 * @param label 标题，可动态
 * @param key key
 * @param icon 图标
 * @param children 子列表
 * @param type 类型
 */
export function getAntdMenuItem(
  label: string | VueElement,
  key: string,
  icon?: any,
  children?: ItemType[],
  type?: 'group',
): ItemType {
  return {
    key,
    icon,
    children,
    label,
    type,
  } as ItemType;
}

/**
 * 递归收集key
 * @param data
 */
export function getAllNodeKeys(data): string[] {
  const keys: string[] = [];
  function traverse(nodes: any[]) {
    nodes.forEach((node) => {
      keys.push(node.id);
      if (node.children) {
        traverse(node.children);
      }
    });
  }
  traverse(data);
  return keys;
}
